package com.ruoyi.community.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.community.mapper.ComplainMapper;
import com.ruoyi.community.domain.Complain;
import com.ruoyi.community.service.IComplainService;

/**
 * 业主投诉Service业务层处理
 * 
 * @author 袁现程
 * @date 2021-08-07
 */
@Service
public class ComplainServiceImpl implements IComplainService 
{
    @Autowired
    private ComplainMapper complainMapper;

    /**
     * 根据id查询业主投诉
     */
    @Override
    public Complain selectComplainById(Long id)
    {
        return complainMapper.selectComplainById(id);
    }

    /**
     * 查询业主投诉列表
     */
    @Override
    public List<Complain> selectComplainList(Complain complain)
    {
        complain.setCommunityId(Long.valueOf(SecurityUtils.getCommunityId()));
        return complainMapper.selectComplainList(complain);
    }

    /**
     * 新增业主投诉
     */
    @Override
    public int insertComplain(Complain complain)
    {
        complain.setCommunityId(Long.valueOf(SecurityUtils.getCommunityId()));
        complain.setUserId(SecurityUtils.getUserID());
        complain.setStatus("未处理");
        complain.setLeaderIntervene(false);
        complain.setLogicDelete(false);
        Date date = DateUtils.getNowDate();
        complain.setCreateTime(date);
        complain.setModifyTime(date);
        return complainMapper.insertComplain(complain);
    }

    /**
     * 修改业主投诉
     */
    @Override
    public int updateComplain(Complain complain)
    {
        return complainMapper.updateComplain(complain);
    }

    /**
     * 批量删除业主投诉
     */
    @Override
    public int deleteComplainByIds(Long[] ids)
    {
        return complainMapper.deleteComplainByIds(ids);
    }

    /**
     * 删除业主投诉信息
     */
    @Override
    public int deleteComplainById(Long id)
    {
        return complainMapper.deleteComplainById(id);
    }

    /**
     * 根据userId查业主投诉列表
     */
    public List<Complain> selectListByUserId() {
        Complain complain = new Complain();
        complain.setUserId(SecurityUtils.getUserID());
        complain.setCommunityId(Long.valueOf(SecurityUtils.getCommunityId()));
        List<Complain> complainList = complainMapper.selectComplainList(complain);
        return complainList;
    }
}
